package h0910;

import java.util.HashSet;

/**
  * @description 快乐数
  * @author 不知名帅哥
  * @date 2024/9/10 18:32
  * @version 1.0
*/
public class HappyNumber {
    public static void main(String[] args) {

    }
    public boolean isHappy(int n) {
        HashSet<Integer> set = new HashSet<>();

        while (n!=1){
            if (set.contains(n)){
                return false;
            }
            set.add(n);
            n=process(n);
        }
        return true;
    }

    private int process(int n) {
        int sum=0;
        while (n!=0){
            int a = n % 10;
            sum+= a * a;
            n/=10;
        }
        return sum;
    }
}
